/**
 * 
 */
package com.hs.pre.module.perinfo;

import java.util.List;

import com.hs.HsBase;
import com.hs.core.db.DBOperator;
import com.hs.core.db.DatabaseConnection;

/**
 * @author shl
 *
 */
public class PreManagerDao {
    /**
     * 编辑方剂
     * @param map
     * @return
     */
	public String editPre(String str){
		String message = null;
		//PreEntry pre = new PreEntry(map);
		System.out.println(str);
//		DBOperator dbo = this.getDBOperator();
//		String sql = HsBase.getAnsiSqlMap().get("preinfo.insert")+"";
//		if(null != map.get("preid")){
//			sql = HsBase.getAnsiSqlMap().get("preinfo.update_all")+"";
//		}
//		int i = dbo.update(sql, pre.getParams());
//		if(i > 0)
//			message = "操作成功";
//		else
//			message = "操作失败";
		return message;
	}
	/**
	 * 删除方剂
	 * @param preId
	 * @return
	 */
	public String deletePre(String preId){
		String message = null;
		DBOperator dbo = this.getDBOperator();
		String sql = HsBase.getAnsiSqlMap().get("preinfo.delete_byid")+"";
		int i = dbo.update(sql, new Object[]{preId});
		if(i > 0)
			message = "操作成功";
		else
			message = "操作失败";
		return message;
	}
	/**
	 * 获得数据库操作类
	 * @return
	 */
	private DBOperator getDBOperator(){
		try { 
			DBOperator dbo = DatabaseConnection.getDBOperator();
			return dbo;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public String  validatePreId(String id){
		String message = "";
		DBOperator dbo = this.getDBOperator();
		String sql = HsBase.getAnsiSqlMap().get("preinfo.validate")+"";
		List resultList = dbo.select(sql, new Object[]{id});
		System.out.println(resultList);
		if(null != resultList && resultList.size()>=1)
			message = "方剂编号【" + id + "】重复，请重新编号";
		return message;
	}
	public String  delPre(String idStr){
		StringBuffer message = new StringBuffer("");
		String[] ids = null;
		if(null != idStr&&idStr.length() > 0){
			idStr = idStr.substring(0,idStr.length()-1);
		    ids = idStr.split(",");
		}
		if(null != ids){
			DBOperator dbo = this.getDBOperator();
			String sql = HsBase.getAnsiSqlMap().get("preinfo.delete_byid")+"";
			for(int i =0;i<ids.length;i++){
				String id = ids[i];
				int result = dbo.update(sql, new Object[]{id});
			}
		} 
		return message.toString();
	}
	
}
